package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.dubbo.mappers.PmsBrandMapper;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.tanhua.model.domain.PmsBrand;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class PmsBrandApiImpl implements PmsBrandApi{
    @Autowired
    private PmsBrandMapper pmsBrandMapper;


    @Override
    public Page<PmsBrand> list(String keyword, Page<PmsBrand> page) {
        LambdaQueryWrapper<PmsBrand> lqw = new LambdaQueryWrapper<>();
        lqw.like(keyword != null ,PmsBrand::getName,keyword);
        return pmsBrandMapper.selectPage(page,lqw);
    }


    /**
     * 批量更新厂家制造商状态
     * @param ids
     * @return factoryStatus
     */
    @Override
    public void updateFactoryStatus(Integer[] ids, Integer factoryStatus) {
        LambdaQueryWrapper<PmsBrand> lqw = new LambdaQueryWrapper<>();
        lqw.in(ids != null,PmsBrand::getId,ids);

        PmsBrand pmsBrand = new PmsBrand();
        pmsBrand.setFactoryStatus(factoryStatus);

        pmsBrandMapper.update(pmsBrand,lqw);
    }


    /**
     * 批量更新显示状态
     * @param ids
     * @param showStatus
     * @return
     */
    @Override
    public void updateShowStatus(Integer[] ids, Integer showStatus) {
        LambdaQueryWrapper<PmsBrand> lqw = new LambdaQueryWrapper<>();
        lqw.in(ids != null,PmsBrand::getId,ids);

        PmsBrand pmsBrand = new PmsBrand();
        pmsBrand.setShowStatus(showStatus);

        pmsBrandMapper.update(pmsBrand,lqw);

    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public PmsBrand findBrandById(Integer id) {
        return pmsBrandMapper.selectById(id);
    }

    /**
     * 更新品牌
     * @param pmsBrand
     * @return
     */
    @Override
    public void updateById(PmsBrand pmsBrand) {
        pmsBrandMapper.updateById(pmsBrand);
    }

    /**
     * 根据id删除品牌
     * @param id
     * @return
     */
    @Override
    public void deleteById(Long id) {
        pmsBrandMapper.deleteById(id);
    }

    @Override
    public void create(PmsBrand pmsBrand) {
        pmsBrandMapper.insert(pmsBrand);
    }
}
